<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const json = {
            a: { b: { c: 1 } },
            d: [1, 2],
        }

        // n为当前值，path为寻找路径  比如{c:1}这个值的path为['a', 'b']
        const dfs = (n, path) => {
            console.log(n, path);
            // 用Object.keys(n) 获取n节点所有的键，然后遍历。
            Object.keys(n).forEach(k => {
                dfs(n[k], path.concat(k));
            })
        }

        dfs(json, [])
        // console.log(Object.keys(json)); // ['a', 'b'];
        // console.log(Object.keys([1,2,3,4])); // ['1','2','3','4'];
    </script>
</body>
</html>